<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>员工管理</title>
    <#include "../common/link.ftl">
    <script>
        //给全选/全不选绑定事件
        $(function () {
            $('#allCb').click(function () {
                //全选/全不选
                $('.cb').prop('checked',$(this).prop('checked'));
            })
            //有其中一个没选上,那就全选框就不选上,给各个复选框添加点击事件
            $('.cb').click(function () {
                if ($('.cb').length != $('.cb:checked').length) {
                    $('#allCb').prop('checked',false)
                }else{
                    $('#allCb').prop('checked',true)
                }
            })
            
            //使用ajax发生请求删除
            $('.btn_delete').click(function () {
                //提示是否删除
                var id = $(this).data('id');
                $.messager.confirm("警告","您是否要删除该条数据?",function () {
                    $.get("/courSeorder/delete.do",{id:id},handlerMessage)
                })
            })

            //模态框
            $('.btn-input').click(function () {
                //点击添加或者编辑的时候,先清除模态框的缓存数据
                $('#editForm input').val('');
                $('#customeridz').val(-1)
                $('#courseidz').val(-1)
                //如果是data开头的,可以使用data方法来接收
                var json = $(this).data("json");
                console.log(json);
                if (json) {
                    $('input[name=id]').val(json.id)
                    $('input[name=money]').val(json.money)
                    $('#customeridz').val(json.customerid)
                    $('#courseidz').val(json.courseid)

                }
                $('#myModal').modal('show');
            })

            //保存
            $('.btn-submit').click(function () {
                //保存数据
                $('#editForm').ajaxSubmit(handlerMessage)
            })


        })
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "../common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="courSeorder"/>
    <#include "../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>课程订单管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <div style="margin: 10px;">
                    <form class="form-inline" id="searchForm" action="/courSeorder/list.do" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">
                        <div class="form-group">
                            <label for="keyword">关键字:</label>
                            <input type="text" class="form-control" id="keyword" name="keyword" value="${qo.keyword!}" placeholder="请输入客户名称">
                        </div>
                        <div class="form-group">
                            <label for="dept"> 销售课程:</label>
                            <select class="form-control" id="sys" name="sns_id">
                                <option value="-1">全部</option>
                                <#list sys as d>
                                    <option value="${d.id}">${d.title!}</option>
                                </#list>
                            </select>
                            <script>
                                $("#sys option[value='${qo.sns_id}']").prop("selected", true);
                            </script>
                        </div>
                        <button id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 查询</button>
                        <@shiro.hasPermission name="courSeorder:input">
                        <a href="#"  class="btn btn-success btn_redirect btn-input">
                            <span class="glyphicon glyphicon-plus"></span> 添加
                        </a>
                        </@shiro.hasPermission>

                    </form>
                </div>
                <table class="table table-hover table-bordered">
                    <thead>
                    <tr>
                        <th><input type="checkbox" id="allCb"></th>
                        <th>编号</th>
                        <th>客户名称</th>
                        <th>销售课程</th>
                        <th>销售时间</th>
                        <th>销售金额</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <#list result.list as courSeorder>
                        <tr>
                            <td><input type="checkbox" class="cb" data-id="${courSeorder.id}"></td>
                            <td>${courSeorder_index+1}</td>
                            <td>${courSeorder.customer.name!}</td>
                            <td>${courSeorder.course.title!}</td>
                            <td>${(courSeorder.inputTime?string('yyyy-MM-dd'))!}</td>
                            <td>${(courSeorder.money)!}</td>
                            <td>
                            <@shiro.hasPermission name="courSeorder:input">
                                <a href="#" class="btn btn-info btn-xs btn_redirect btn-input" data-json='${courSeorder.json}'>
                                    <span class="glyphicon glyphicon-pencil"></span> 编辑
                                </a>
                            </@shiro.hasPermission>
                        <@shiro.hasPermission name="courSeorder:delete">
                                <a href="#" class="btn btn-danger btn-xs btn_delete" data-id="${courSeorder.id}">
                                    <span class="glyphicon glyphicon-trash"></span> 删除
                                </a>
                        </@shiro.hasPermission>
                            </td>
                        </tr>
                    </#list>
                </table>
                <!--分页-->
                <#include "../common/page.ftl">
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl">
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">课程订单新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/courSeorder/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden"  name="id">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="customer.id" class="col-sm-3 control-label">选择客户：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="customeridz" name="customer.id">
                                <option value="-1">请选择</option>
                                <#list (empsAll)! as emp>
                                    <#if emp??>
                                    <option value="${(emp.id)!}">${(emp.name)!}</option>
                                    </#if>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="course.id" class="col-sm-3 control-label">选择课程：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="courseidz" name="course.id">
                                <option value="-1">请选择</option>
                                <#list (sys)! as c>
                                    <#if c??>
                                    <option value="${(c.id)!}">${(c.title)!}</option>
                                    </#if>
                                </#list>
                            </select>

                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="number" class="col-sm-3 control-label">销售金额：</label>
                        <div class="col-sm-6">
                            <input type="number" class="form-control" id="money" name="money"
                                   placeholder="请输入销售金额">
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submit">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
